//
//  PeopleNumberPopView.m
//  TQY
//
//  Created by 甘世清 on 2024/10/4.
//

#import "PeopleNumberPopView.h"

@implementation PeopleNumberPopView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = UIColor.whiteColor;
    self.layer.cornerRadius = 10;
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"活动人数");
    label.textColor = SQColor333333;
    label.font = FONT_MEDIUM(16);
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(24);
    }];
    
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 6;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.mas_equalTo(SCREEN_WIDETH/2.f);
            make.height.mas_equalTo(44);
        make.top.equalTo(self).offset(60);
    }];
    [bgView addSubview:self.leftBtn];
    [bgView addSubview:self.rightBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(bgView);
            make.width.mas_equalTo(SCREEN_WIDETH/4.f-1);
    }];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(bgView);
            make.width.mas_equalTo(SCREEN_WIDETH/4.f-1);
    }];
    
    [self addSubview:self.oneView];
    [self addSubview:self.towView];
    [self.oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self).offset(120);
        make.width.mas_equalTo(SCREEN_WIDETH);
        make.height.mas_equalTo(130);
    }];
    [self.towView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.oneView.mas_right);
        make.top.equalTo(self).offset(120);
        make.width.mas_equalTo(SCREEN_WIDETH);
        make.height.mas_equalTo(130);
    }];
    
    [self.oneView addSubview:self.totalField];
    [self.totalField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.oneView);
            make.centerX.equalTo(self.oneView).offset(30);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(40);
    }];
    
    UILabel * totalLabel = [[UILabel alloc]init];
    totalLabel.text = SQNSLocalString(@"总人数:");
    totalLabel.textColor = SQColor333333;
    totalLabel.font = FONT_REGULAR(14);
    [self.oneView addSubview:totalLabel];
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.oneView);
        make.right.equalTo(self.totalField.mas_left).offset(-10);
    }];
    
    [self.towView addSubview:self.nanField];
    [self.nanField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.towView).offset(-24);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(40);
            make.centerX.equalTo(self.towView).offset(30);
    }];
    [self.towView addSubview:self.nvField];
    [self.nvField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.towView).offset(24);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(40);
        make.centerX.equalTo(self.towView).offset(30);
    }];
   
    
    UILabel * nanLabel = [[UILabel alloc]init];
    nanLabel.text = SQNSLocalString(@"男性:");
    nanLabel.textColor = SQColor333333;
    nanLabel.font = FONT_REGULAR(14);
    [self.towView addSubview:nanLabel];
    [nanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nanField);
        make.right.equalTo(self.nanField.mas_left).offset(-10);
    }];
    
    UILabel * nvLabel = [[UILabel alloc]init];
    nvLabel.text = SQNSLocalString(@"女性:");
    nvLabel.textColor = SQColor333333;
    nvLabel.font = FONT_REGULAR(14);
    [self.towView addSubview:nvLabel];
    [nvLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nvField);
        make.right.equalTo(self.nvField.mas_left).offset(-10);
    }];
  
    [self addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.mas_equalTo(SCREEN_WIDETH-40);
            make.height.mas_equalTo(50);
            make.top.equalTo(self.oneView.mas_bottom).offset(30);
    }];
    
    WS(weakSelf);
    [self.leftBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_clickButton:button];
    }];
    [self.rightBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_clickButton:button];
    }];
}
-(void)SQ_clickButton:(SQCustomButton*)button{
    if (button == self.leftBtn) {
        self.isAll = YES;
        self.leftBtn.backgroundColor = SQColor3DA59D;
        self.rightBtn.backgroundColor = SQHexColor(@"#000000", 0.5);
        [self.oneView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self);
        }];
    } else {
        self.isAll = NO;
        self.rightBtn.backgroundColor = SQColor3DA59D;
        self.leftBtn.backgroundColor = SQHexColor(@"#000000", 0.5);
        [self.oneView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(-SCREEN_WIDETH);
        }];
    }
    [UIView animateWithDuration:0.2 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)setIsAll:(BOOL)isAll{
    _isAll = isAll;
    if (isAll) {
        self.leftBtn.backgroundColor = SQColor3DA59D;
        self.rightBtn.backgroundColor = SQHexColor(@"#000000", 0.5);
        [self.oneView mas_updateConstraints:^(MASConstraintMaker *make) {
              make.left.equalTo(self);
        }];
    } else {
       
        self.rightBtn.backgroundColor = SQColor3DA59D;
        self.leftBtn.backgroundColor = SQHexColor(@"#000000", 0.5);
        [self.oneView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(-SCREEN_WIDETH);
        }];
    }
    [UIView animateWithDuration:0.2 animations:^{
        [self layoutIfNeeded];
    }];
}

- (SQCustomButton *)addButton{
    if (!_addButton) {
        _addButton = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _addButton.backgroundColor = SQColor3DA59D;
        _addButton.textColor = SQColor(@"#FFFFFF");
        _addButton.layer.cornerRadius = 25;
        _addButton.layer.masksToBounds = YES;
        _addButton.text = SQNSLocalString(@"确认");
        _addButton.font = FONT_MEDIUM(16);
    }
    return _addButton;
}

- (SQCustomButton *)leftBtn{
    if (!_leftBtn) {
        _leftBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _leftBtn.text = SQNSLocalString(@"按总数");
        _leftBtn.font = FONT_REGULAR(14);
        _leftBtn.backgroundColor = SQColor3DA59D;
        _leftBtn.textColor = UIColor.whiteColor;
    }
    return _leftBtn;
}

- (SQCustomButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _rightBtn.text = SQNSLocalString(@"按性别");
        _rightBtn.font = FONT_REGULAR(14);
        _rightBtn.backgroundColor = SQHexColor(@"#000000", 0.5);
        _rightBtn.textColor = UIColor.whiteColor;
    }
    return _rightBtn;
}
- (UIView *)oneView{
    if (!_oneView) {
        _oneView = [[UIView alloc]init];
        _oneView.backgroundColor = UIColor.whiteColor;
    }
    return _oneView;
}

- (UIView *)towView{
    if (!_towView) {
        _towView = [[UIView alloc]init];
        _towView.backgroundColor = UIColor.whiteColor;
    }
    return _towView;
}
- (UITextField *)totalField{
    if (!_totalField) {
        _totalField = [[UITextField alloc]init];
        _totalField.font  = FONT_BOLD(18);
        _totalField.textColor = UIColor.blackColor;
        _totalField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
        _totalField.layer.cornerRadius = 4;
        _totalField.layer.borderColor = SQColor333333.CGColor;
        _totalField.layer.borderWidth = 2;
        _totalField.textAlignment = NSTextAlignmentCenter;
    }
    return _totalField;
}
- (UITextField *)nanField{
    if (!_nanField) {
        _nanField = [[UITextField alloc]init];
        _nanField.font  = FONT_BOLD(18);
        _nanField.textColor = UIColor.blackColor;
        _nanField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
        _nanField.layer.borderColor = SQColor333333.CGColor;
        _nanField.textAlignment = NSTextAlignmentCenter;
        _nanField.layer.borderWidth = 2;
    }
    return _nanField;
}
- (UITextField *)nvField{
    if (!_nvField) {
        _nvField = [[UITextField alloc]init];
        _nvField.font  = FONT_BOLD(18);
        _nvField.textColor = UIColor.blackColor;
        _nvField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
        _nvField.layer.borderColor = SQColor333333.CGColor;
        _nvField.layer.borderWidth = 2;
        _nvField.textAlignment = NSTextAlignmentCenter;
    }
    return _nvField;
}
@end
